package com.crpc.manager;


import com.crpc.common.utils.zookeeper.ZookeeperNode;
import com.crpc.common.utils.zookeeper.ZookeeperUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooKeeper;

import java.util.ArrayList;

import static com.crpc.common.utils.zookeeper.ZookeeperUtils.createNode;

/**
 * @author CLOUD
 * @version 1.0
 * @description:
 * @date 2023/9/7 15:46
 */

@Slf4j
public class ManagerApplication {
    public static void main(String[] args) throws InterruptedException {
        //创建基础目录

        try {
            ZooKeeper zooKeeper = ZookeeperUtils.createZooKeeper();
            //定义节点和数据
            String basePth = "/crpc-metadata";
            String providerPath = basePth + "/providers";
            String consumerPath = basePth + "/consumers";
            ZookeeperNode build1 = ZookeeperNode.builder().nodePath(basePth).build();
            ZookeeperNode build2 = ZookeeperNode.builder().nodePath(providerPath).build();
            ZookeeperNode build3 = ZookeeperNode.builder().nodePath(consumerPath).build();
            ArrayList<ZookeeperNode> nodes = new ArrayList<>();
            nodes.add(build1);
            nodes.add(build2);
            nodes.add(build3);
            nodes.stream().forEach(node -> createNode(node, zooKeeper, null, CreateMode.PERSISTENT));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
